<template>
    <el-dialog
        title="重置密码"
        :visible.sync="dialogStatus"
        width="400px"
        :close-on-click-modal="false"
        :before-close="closeDialog"
        top="30vh"
    >
        <div class="dialog-title" slot="title">重置密码</div>
        <div class="dialog-body">
            <el-form ref="form" :model="form" label-width="">
                <el-form-item label="" prop="password" :rules="[{required:true,message:'请输入新密码',trigger:'blur'}]" style="margin-bottom:15px;">
                    <el-input type="password" size="small" v-model="form.password"></el-input>
                </el-form-item>
                <el-form-item style="text-align:center;">
                    <el-button type="primary" size="small" @click="onSubmit('form')">立即提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </el-dialog>
</template>

<script>
export default {
    data(){
        return {
            dialogStatus:false,
            form:{
                userId:'',
                password:'',
            },
        }
    },
    mounted() {
    },
    methods:{
        // 提交数据
        onSubmit(form){
            this.$refs[form].validate((valid) => {
                if(valid){
                    this.$http.post('/api/sysuser/resetpwd', this.form).then(result => {
                        if(result.code == 200){
                            this.$message.success({
                                message:result.msg,
                                onClose:_ => {}
                            });
                            this.closeDialog();
                            this.$emit('refersh', null);
                        }else{
                            this.$message.error(result.msg);
                        }
                    });
                }
            });
        },
        // 显示弹窗
        openDialog(e){
            this.form.userId = e.userId;
            this.dialogStatus = true;
        },
        // 关闭回调
        closeDialog(e){
            this.dialogStatus = false;
            this.$refs['form'].resetFields();
        },
    }
}
</script>

<style scoped>

</style>
